package com.daotingli.backendprograms.Controller.Admin.Reader;

import com.daotingli.backendprograms.Service.Admin.Reader.ReaderService;
import com.daotingli.backendprograms.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping
public class ReaderController {
    @Autowired
    private ReaderService readerService;
    /**
     * 获取所有读者
     * @return Map id,name,sex,identity,phone,address,email,password
     */
    @RequestMapping(path = "/admin/reader/getAll",method = RequestMethod.POST)
    public Result getAllReaders()
    {
        return readerService.getAllReaders();
    }
    @RequestMapping(path = "/admin/reader/add",
            method = RequestMethod.POST,
            params = {"username","password","identity","userphone","userstate"})
    public Result addReader(@RequestParam("username") String username,
                            @RequestParam("password") String password,
                            @RequestParam("identity") String identity,
                            @RequestParam("userphone") String userphone,
                            @RequestParam("userstate") String userstate)
        {
            return readerService.addReader(username,password,identity,userphone,userstate);
        }

        @RequestMapping(path = "/admin/reader/delete",
                method = RequestMethod.POST,
                params = {"id"})
    public Result deleteReader(@RequestParam("id") Integer id){
        return readerService.deleteReader(id);
        }
    @RequestMapping(path = "/admin/reader/update",
            method = RequestMethod.POST,
            params = {"id","username","password","identity","userphone","userstate"})
    public Result updateReader(@RequestParam("id") Integer id,
                               @RequestParam("username") String username,
                               @RequestParam("password") String password,
                               @RequestParam("identity") String identity,
                               @RequestParam("userphone") String userphone,
                               @RequestParam("userstate") String userstate)
    {
        return readerService.updateReader(id,username,password,identity,userphone,userstate);
    }
}
